package robotleMvc.frameworks.glass
{
	import _Pan3D.program.Program3DManager;
	import _Pan3D.program.shaders.GlassShader;

	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display3D.Context3D;
	import flash.display3D.Program3D;
	import flash.events.Event;
	import flash.net.URLRequest;

	import org.robotlegs.mvcs.Mediator;

	import robotleMvc.ui.glass.GlassDisplay3DSprite;
	import robotleMvc.ui.glass.GlassView;

	public class GlassMeddiator extends Mediator
	{
		[Inject]
		public var glassView:GlassView;
		private var display3DContainer:Object;
		private var context3D:Context3D;
		private var _glassDisplay3DSprite:GlassDisplay3DSprite;

		public function GlassMeddiator()
		{
			super();
		}

		override public function onRegister():void
		{
			display3DContainer=glassView.display3DContainer;
			context3D=glassView.context3D;
			initGlass();

			this.addContextListener(GlassEvent.UP_NEW_GLASS_INFO_PIC, upNewGlassInfoPic);

		}

		private function initGlass():void
		{
			_glassDisplay3DSprite=new GlassDisplay3DSprite(context3D);
			_glassDisplay3DSprite.url="cao03_yizhan"
			_glassDisplay3DSprite.x=0
			_glassDisplay3DSprite.y=-10
			_glassDisplay3DSprite.z=0
			_glassDisplay3DSprite.scale=10;
			display3DContainer.addChild(_glassDisplay3DSprite);

			var treeShaderProgram3d:Program3D=Program3DManager.getInstance().getProgram(GlassShader.GLASS_SHADER);
			display3DContainer.setProgram3D(treeShaderProgram3d);
		}

		private function upNewGlassInfoPic(evt:GlassEvent):void
		{
			loadGlassPic()
		}

		public function loadGlassPic():void
		{

			var _picloader:Loader=new Loader();
			var _picloaderURL:URLRequest=new URLRequest("../_File/nijia2/" + "ground/glassInfoPic.jpg");
			_picloader.load(_picloaderURL);
			_picloader.contentLoaderInfo.addEventListener(Event.COMPLETE, _load_pic_ok);
		}

		private function _load_pic_ok(event:Event):void
		{
			var loader:Loader=Loader(event.target.loader);
			var image:Bitmap=Bitmap(loader.content);
			_glassDisplay3DSprite.setGlassInfoBitmapdata(image.bitmapData);

		}


	}
}
